unit dqc;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, base, StdCtrls, Buttons, ExtCtrls, drawQC, ComCtrls, Grids,
  DBGrids, RzDBGrid, RzButton, strUtils, DB;

type
  Tdqcfrm = class(Tbasefrm)
    palbg: TPanel;
    drawQcfrm: TdrawQcfrm;
    panCtrl: TPanel;
    RzDBGrid1: TRzDBGrid;
    Panel1: TPanel;
    DateTimePicker1: TDateTimePicker;
    comRfid: TComboBox;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    DataSource: TDataSource;
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure DateTimePicker1Change(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure comRfidChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Refreshdqc;
  end;

var
  dqcfrm: Tdqcfrm;

implementation

{$R *.dfm}

uses
  includefile, dbmodule;

procedure Tdqcfrm.Refreshdqc;
var
  rfid:string;
  dt:Tdatetime;
begin
  rfid:=Trim(LeftStr(comRfid.Text,10));
  dt:=DateTimePicker1.Date;
  //RzDBGrid1.DataSource.DataSet.Active:=False; 
  with dbmodulefrm.dbtmpqry do begin
    active :=False;
    sql.Clear;
    sql.Add('SELECT FORMAT([DATETIME],"hh:mm:ss") as [DATETIME], FORMAT(NW,"0.00") as NW, TRAYS from RECORD');
    SQL.Add(Format('WHERE DATETIME>=#%s#',[FormatDateTime('YYYY-MM-DD',dt)]));
    SQL.Add(Format('AND DATETIME<#%s#',[FormatDateTime('YYYY-MM-DD',dt+1)]));
    sql.Add(Format('AND Right(RFID,%d)=''%s''',[RFIDLEN,rfid]));
    Sql.Add('Order By RECORD.DATETIME');
    execsql;
    active:=True;
  end;
  DataSource.DataSet:=dbmodulefrm.dbtmpqry;
  drawQcfrm.getChatData(rfid,dt); 
end;

procedure Tdqcfrm.FormCreate(Sender: TObject);
var
  I:integer;
begin
  inherited;
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption(name,TLabel(Components[I]).Tag);
    end;
    if Components[I] is TRzBitBtn then begin
      if 0<>TRzBitBtn(Components[I]).Tag then
        TRzBitBtn(Components[I]).Caption:=
                GetCaption(name,TRzBitBtn(Components[I]).Tag);
    end;
  end;
  dbmodulefrm.getRFIDName(comRfid.Items);
end;

procedure Tdqcfrm.RzBitBtn1Click(Sender: TObject);
begin
  inherited;
  DateTimePicker1.Date:=DateTimePicker1.Date-1;
  Refreshdqc;
end;

procedure Tdqcfrm.RzBitBtn2Click(Sender: TObject);
begin
  inherited;
  DateTimePicker1.Date:=DateTimePicker1.Date+1;
  Refreshdqc;
end;

procedure Tdqcfrm.DateTimePicker1Change(Sender: TObject);
begin
  inherited;
  Refreshdqc;
end;

procedure Tdqcfrm.btnCloseClick(Sender: TObject);
begin
  dbmodulefrm.dbtmpqry.Active:=False;
  DataSource.DataSet:=Nil;
  inherited;
end;

procedure Tdqcfrm.comRfidChange(Sender: TObject);
begin
  inherited;
  Refreshdqc;
end;

end.
